/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>Project: app2022 - List2
 * <p>Powered by webrx On 2022-01-14 15:30:26
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class List2 {
    public static void main(String[] args) {
        //实例化ArrayList<String> 使用泛型
        var list = new ArrayList<String>();

        list.add("javascript");

        list.add(0,"java");

        list.addAll(1, List.of("php","python","ruby","python","mysql","python"));

        //遍历集合方法一
        for (String s : list) {
            System.out.println(s);
        }

        //遍历集合方法二
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }

        //遍历集合方法三
        list.forEach(System.out::println);


        System.out.println(list.contains("html")); //false

        //true
        System.out.println(list.containsAll(List.of("java","mysql")));

        System.out.println(list.indexOf("java"));//0
        System.out.println(list.lastIndexOf("java"));//0

        //判断是不是空的
        System.out.println(list.isEmpty());//false

        System.out.println(list);
        System.out.println(list.get(0));
        //删除从左边开始第一次出现的python
        //list.remove("python");
        //删除指定位置的内容
        //list.remove(3);
        //删除所有python
        //list.removeAll(List.of("python"));
        //删除所有元素，清空集合
        list.clear();
        //返回list元素个数
        System.out.println(list.size());

        System.out.println(list);

    }
}
